package org.util.properties;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

/**
 * 
 * 属性操作工具类对象;
 * 
 * @Title: ProperUtil.java
 * @Description:评师网管理后台(一期)
 * @Copyright: Copyright (c) 2011
 * @Company:北京学邦时代
 * @author 苗有虎
 * @date Apr 13, 2012 10:31:50 AM
 * @version V4.0
 */

public class ProperUtil extends XMLProcessor {

	/**
	 * 修改属性值;
	 * 
	 * @param fileUrl
	 * @param Key
	 * @param value
	 */
	public void setPropertyValue(String Key, Object value) {
		String fileUrl = ServletActionContext.getRequest().getRealPath(
				"/WEB-INF/classes/globalMessages_zh_CN.properties");
		File file = new File(fileUrl);
		Properties pro = new Properties();
		FileInputStream fis = null;
		BufferedInputStream bis = null;
		try {
			fis = new FileInputStream(file);
			bis = new BufferedInputStream(fis);
			pro.load(bis);
			FileOutputStream fos = new FileOutputStream(file);
			pro.setProperty(Key, String.valueOf(value));
			pro.store(fos, null);
			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String getPropertyValue(String Key) {
		String fileUrl = ServletActionContext.getRequest().getRealPath(
				"/WEB-INF/classes/globalMessages_zh_CN.properties");
		File file = new File(fileUrl);
		Properties pro = new Properties();
		FileInputStream fis = null;
		BufferedInputStream bis = null;
		String hehe = "";
		try {
			fis = new FileInputStream(file);
			bis = new BufferedInputStream(fis);
			pro.load(bis);
			FileOutputStream fos = new FileOutputStream(file);
			hehe = pro.getProperty(Key);
			pro.store(fos, null);
			fos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hehe;
	}

}
